#include <windows.h>

#include "dxdiag_res.h"
#include "dxdiagcom.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);

/* Sound tab callback procedure */
LRESULT CALLBACK Sound_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

    HBRUSH g_hbrBackground = CreateSolidBrush(RGB(255,255,255));
    DWORD tests;
    switch(uMsg) {
        case WM_INITDIALOG:
            return TRUE;
        case WM_CTLCOLORSTATIC:
            if (GetDlgCtrlID((HWND) lParam) == SOUNDTAB_NOTESEDIT)
            {
                return (LRESULT)g_hbrBackground;
            }
                case WM_COMMAND:
                        if (LOWORD(wParam) == SOUNDTAB_DSOUNDBTN)
                        {
                            DSoundTest_test(&tests,hWnd);
                        }
                        break;
        default:
            break;
    }

    return FALSE;
}

BOOL SoundInfo_GetInfo(DxDiagCOM* pcom, SoundInfo* info)
{
    IDxDiagContainer* soundEnum;
    IDxDiagContainer* sound;

    /* Get the DirectSound container */
     if (FAILED(DxDiagCOM_GetContainer(pcom->root, (LPCWSTR)("DxDiag_DirectSound"), &soundEnum)))
        return FALSE;

    /* Get the sound devices container */
     if (FAILED(DxDiagCOM_GetContainer(soundEnum, (LPCWSTR)("DxDiag_SoundDevices"), &soundEnum)))
        return FALSE;

    /* Get the primary sound device*/
     if (FAILED(DxDiagCOM_GetContainer(soundEnum, (LPCWSTR)("0"), &sound)))
        return FALSE;

    /* Get the information */
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZDESCRIPTION)), &info->name);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZHARDWAREID)), &info->hardwareID);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZMANUFACTURERID)), &info->manufacturerID);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZPRODUCTID)), &info->productID);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZTYPE)), &info->type);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZDRIVERPATH)), &info->filename);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZDRIVERVERSION)), &info->version);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZDRIVERATTRIBUTES)), &info->attributes);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZDRIVERDATEENGLISH)), &info->date);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZOTHERDRIVERS)), &info->otherFiles);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZPROVIDER)), &info->provider);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)("szProvider"), &info->provider);
    DxDiagCOM_GetStringProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_SZNOTESENGLISH)), &info->notes);
    DxDiagCOM_GetIntegerProperty(sound, (LPCWSTR)(DxDiag_LoadString(SOUND_BDRIVERSIGNED)), &info->whql);

    return TRUE;
}

void Sound_DisplayData()
{
    HWND hWnd;

     /* Device box */
    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_NAMEDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.name);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_DEVICEDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.hardwareID);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_MFGDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.manufacturerID);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_PRODDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.productID);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_TYPEDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.type);

    /* Driver box */
    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_DRIVERDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.filename);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_VERSIONDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.version);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_DATEDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.date);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_FILESDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.otherFiles);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_PROVDATA);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.provider);

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_WHQLDATA);

    if (soundInfo.whql)
        SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)"Yes\n");
    else
        SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)"No\n");

    hWnd = GetDlgItem(hTabDisplay, SOUNDTAB_NOTESEDIT);
    SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM)soundInfo.notes);
}

void Sound_SaveText(FILE* pFile)
{
    /*
    fwprintf(pFile, "------------------\n");
    fwprintf(pFile, "Sound Devices\n");
    fwprintf(pFile, "------------------\n");

    fwprintf(pFile, "           Description: %s\n", soundInfo.name);
    fwprintf(pFile, "Default Sound Playback: %s\n", "Yes");
    fwprintf(pFile, "Default Voice Playback: %s\n", "Yes");
    fwprintf(pFile, "           Hardware ID: %s\n", soundInfo.hardwareID);
    fwprintf(pFile, "       Manufacturer ID: %s\n", soundInfo.manufacturerID);
    fwprintf(pFile, "            Product ID: %s\n", soundInfo.productID);
    fwprintf(pFile, "                  Type: %s\n", soundInfo.type);
    fwprintf(pFile, "           Driver Name: %s\n", soundInfo.filename);
    fwprintf(pFile, "        Driver Version: %s\n", soundInfo.version);
    fwprintf(pFile, "     Driver Attributes: %s\n", soundInfo.attributes);
    fwprintf(pFile, "                  Date:  %s\n", soundInfo.date);
    fwprintf(pFile, "           Other Files: %s\n", soundInfo.otherFiles);
    fwprintf(pFile, "       Driver Provider: %s\n\n", soundInfo.provider);
    */
}

void Sound_SaveXML(XML_Node* root)
{
    XML_Node* soundDevicesXML;
    soundDevicesXML = XML_insertChildNode(root,(LPCWSTR)(DxDiag_LoadString(SOUND_XML_SOUNDDEVICES)), NULL);
    soundDevicesXML = XML_insertChildNode(soundDevicesXML,(LPCWSTR)(DxDiag_LoadString(SOUND_XML_SOUNDDEVICE)), NULL);

    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DESCRIPTION)), soundInfo.name);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_HARDWAREID)), soundInfo.hardwareID);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_MANUFACTURERID)), soundInfo.manufacturerID);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_PRODUCTID)), soundInfo.productID);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_TYPE)), soundInfo.type);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERNAME)), soundInfo.filename);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERVERSION)), soundInfo.version);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERLANGUAGE)), NULL);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERBETA)), NULL);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERDEBUG)), NULL);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERWHQLLOGO)), NULL);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERDATE)), soundInfo.date);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_DRIVERSIZE)), NULL);
    XML_insertChildNode(soundDevicesXML, (LPCWSTR)(DxDiag_LoadString(SOUND_XML_OTHERFILES)), NULL);
}
